package com.qst0915.proxy;

import com.qst0915.dao.UserDao;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class UserDaoProxy implements InvocationHandler {
    private UserDao userDao;
    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        MyAspect myAspect=new MyAspect();
        myAspect.log1();
        Object obj=method.invoke(userDao,objects);
        myAspect.log2();
        return obj;
    }
    public Object createProxy(UserDao userDao ){
        this.userDao=userDao;
        ClassLoader classLoader=UserDaoProxy.class.getClassLoader();
        Class[] clazz=userDao.getClass().getInterfaces();
        return Proxy.newProxyInstance(classLoader,clazz,this);
    }
}
